package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class Dvd here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class Dvd
{
    // instance variables - replace the example below with your own
    private long id;
    private String titel;
    private String kunstner;
    private String udgivelsesdato;
    private ArrayList<eksemplar> ex;

 
    /**
    * Constructor for objects of class Dvd
    * @version (0.1)
    * @param id The id of the dvd
    * @param kunstner The name of the artist
    * @param udgivelsesdato The date of dvd creation
    * @param ex A arraylist containing the different copy of the same dvd
    */
    public Dvd(long id, String titel, String kunstner, String udgivelsesdato)
    {
        // initialise instance variables
        this.id = id;
        this.titel = titel;
        this.kunstner = kunstner;
        this.udgivelsesdato = udgivelsesdato;
        ex = new ArrayList<eksemplar>();
    }
    
    /**
     * Return the id of the dvd
     * @return id The id of the dvd
     */
    public long getId()
    {
        return id;
    }
    
    /**
     * Return the title of the dvd
     * @return title The title of the dvd
     */
    public String getTitel()
    {
        return titel;
    }
    
    /**
     * Return the name of the artist
     * @return kunstner The name of the artist
     */
    public String getKunstner()
    {
        return kunstner;
    }
    
    /**
     * The date of the dvd release
     * @return udgivelsesdato The date of the dvd release
     */
    public String getUdgivelsesDato()
    {
        return udgivelsesdato;
    }
    
    /**
     * Set the param of the dvd
     * @param id The id of the dvd
     */
    public void setId(long id)
    {
        this.id = id;
    }
    
    /**
     * Set the param of the dvd
     * @param title The title of the dvd
     */
    public void setTitel(String titel)
    {
        this.titel = titel;
    }
    
    /**
     * Set the param of the dvd
     * @param kunstner The artist of the dvd
     */
    public void setKunstner(String kunstner)
    {
        this.kunstner = kunstner;
    }
    
    /**
     * Set the param of the dvd
     * @param udgivelsesdato The date of the dvd release
     */
    public void setUdgivelsesDato(String udgivelsesdato)
    {
        this.udgivelsesdato = udgivelsesdato;
    }
    
    /**
     * Add a eksemplar to a the dvd
     * @param e The object of the eksemplar to add to dvd
     */
    public void addEksemplar(eksemplar e)
    {
        ex.add(e);
    }
    
    /**
     * Search the dvd container for a specific copy
     * @param serienr The serial number of a dvd
     * @return eksemplar Return the dvd whit the serialnumber
     */
    public eksemplar searchEksemplar(String serienr)
    {
        int index = 0;
        int index2 = 0;
        boolean found = false;
        while(index < ex.size())
        {
            eksemplar eks = ex.get(index);
            if(eks.getSerienr().equals(serienr))
            {
                found = true;
                index2 = index;
            }
            index++;
        }
        return ex.get(index2);
    }
    
   public void listAllEksemplar()
   {
       for(eksemplar eks : ex)
       {
           eks.print();
       }
   }
   
    /**
     * Print the dvd details
     */
    public void print()
    {
        System.out.println("ID:              " + id);
        System.out.println("Titel:           " + titel);
        System.out.println("Kunstner:        " + kunstner);
        System.out.println("Udgivelsesdato:  " + udgivelsesdato);
        listAllEksemplar();
    }
   
    /**
     * Create a copy of the dvd and add the eksemplar details
     * @param serienr The serial number of the specifik dvd
     * @param anskafdato The date tde dvd i bought
     * @param dvd The description of the dvd
     */
    public void createEksemplar(String serienr, String anskafdato, String anskafpris, String dvd)
    {
        eksemplar eks = new eksemplar(serienr, anskafdato, anskafpris, dvd);
        ex.add(eks);
    }
    
      
    public void deleteEksemplar(String serienr)
    {
        int index = 0;
        boolean found = false;
        while(index < ex.size() && found != true)
        {
            eksemplar eks = ex.get(index);
            if(eks.getSerienr().equals(serienr))
            {
                found = true;
                ex.remove(eks);
            }
            else
            {
                index++;
            }
        }
        
    }
    
    public String searchEksemplar2(String serienr)
    {
        String serie = null;
        for(eksemplar eks : ex)
        {
            if(eks.getSerienr() == serienr)
            {
                serie = serienr;
            }
        }
        return serie;
    }
    

   
   
}
